//
//  TGMCollectionViewMoreCell.m
//  TravelGuideHD
//
//  Created by xiaofeng on 14-9-2.
//  Copyright (c) 2014年 mafengo Inc. All rights reserved.
//

#import "TGMCollectionViewMoreCell.h"
#import "TGMActivityIndicatorView.h"

@implementation TGMCollectionViewMoreCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        _infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 13, self.boundsWidth, 14)];
        _infoLabel.font = [UIFont systemFontOfSize:13];
        _infoLabel.backgroundColor = [UIColor clearColor];
        _infoLabel.textAlignment = NSTextAlignmentCenter;
        _infoLabel.textColor = [UIColor colorWithRed:120.0/255.0 green:120.0/255.0 blue:120.0/255.0 alpha:1.0];
        _infoLabel.autoresizesSubviews = UIViewAutoresizingFlexibleWidth;
        [self addSubview:_infoLabel];
        
        _activityIndicatorView = [TGMActivityIndicatorView defaultActivityIndicatorView];
        //        _activityIndicatorView
        _activityIndicatorView.color = C_RGB(0xfa9f00);
        _activityIndicatorView.hidesWhenStopped = YES;
        _activityIndicatorView.hidden = YES;
        [self addSubview:_activityIndicatorView];
        
        _maskClickControl = [[UIControl alloc] initWithFrame:self.bounds];
        _maskClickControl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [_maskClickControl addTarget:self action:@selector(cellClicked) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_maskClickControl];
    }
    return self;
}

- (void)cellClicked
{
    if (self.delegate)
    {
        [self.delegate collectionViewMoreCellDidSelected:self];
    }
}

- (void)layoutSubviews
{
    CGFloat centerX = self.frame.size.width * 0.5;
    CGFloat centerY = self.frame.size.height * 0.5;
    
    _infoLabel.centerX = centerX;
    _activityIndicatorView.center = CGPointMake(centerX, centerY);
}

- (void)setInfoText:(NSString*)infoString forState:(MoreCellState)state;
{
    _state = state;
    if (_state == MoreCellState_Loading)
    {
        _activityIndicatorView.hidden = NO;
        [_activityIndicatorView startAnimating];
        _infoLabel.hidden = YES;
        
        //        _infoLabel.frame = CGRectMake(_activityIndicatorView.frameX + _activityIndicatorView.frameWidth + 5, 15, 200, 15);
    }
    else
    {
        [_activityIndicatorView stopAnimating];
        _infoLabel.hidden = NO;
        _infoLabel.text = infoString;
        
//        _infoLabel.frame = CGRectMake(10, 13, 205, 14);
    }
}

@end
